package com.manthano.security.user.service;

import java.util.Collection;
import java.util.TreeSet;
import java.util.UUID;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class AbstractUser implements UserDetails
{

	private static final long				serialVersionUID	= 1L;

	private final String					username;												// equals
																									// UNID
	private String							password;
	private String							firstname;
	private String							lastname;

	private Collection<GrantedAuthority>	authorities			= new TreeSet<GrantedAuthority>();

	public AbstractUser()
	{
		this.username = UUID.randomUUID().toString();
	}

	public AbstractUser(String username)
	{
		this.username = username;
	}

	@Override
	public Collection<GrantedAuthority> getAuthorities()
	{
		return authorities;
	}

	@Override
	public String getPassword()
	{
		return password;
	}

	@Override
	public String getUsername()
	{
		return username;
	}

	public String getFirstname()
	{
		return firstname;
	}

	public String getLastname()
	{
		return lastname;
	}

	@Override
	public boolean isAccountNonExpired()
	{
		return true;
	}

	@Override
	public boolean isAccountNonLocked()
	{
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired()
	{
		return true;
	}

	@Override
	public boolean isEnabled()
	{
		return true;
	}

	@Override
	public String toString()
	{
		return "AbstractUser [username=" + username + ", firstname=" + firstname + ", lastname=" + lastname
				+ ", authorities=" + authorities + "]";
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public void setLastname(String lastname)
	{
		this.lastname = lastname;
	}

	public void setFirstname(String firstname)
	{
		this.firstname = firstname;
	}

	public void setAuthorities(Collection<GrantedAuthority> authorities)
	{
		this.authorities = authorities;
	}

}
